//
//  CZMainViewController.swift
//  CZVVeiboPre27
//
//  Created by 范英强 on 16/4/15.
//  Copyright © 2016年 范英强. All rights reserved.
//

import UIKit

class CZMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let tabBar = CZTabBar()
        
        tabBar.czDelegate = self
        
        //self.tabBar = tabBar
        
        setValue(tabBar, forKey: "tabBar")
        
        // 添加子控制器
        
        addChildViewController(CZHomeViewController(), title: "首页", imgName: "tabbar_home")
        addChildViewController(CZMessageViewController(), title: "消息", imgName: "tabbar_message_center")
        addChildViewController(CZDiscoverViewController(), title: "发现", imgName: "tabbar_discover")
        addChildViewController(CZProfileViewController(), title: "我", imgName: "tabbar_profile")
        
    }
    
    func addChildViewController(childController: UIViewController, title: String, imgName: String) {
        
        let childController = CZHomeViewController()
        // 设置title
        childController.title = title
        // 设置图片
        childController.tabBarItem.image = UIImage(named: imgName)
        childController.tabBarItem.selectedImage = UIImage(named: "\(imgName)_selected")
        
        addChildViewController(UINavigationController(rootViewController: childController))
    }

}

extension CZMainViewController: CZTabBarDelegate{
    func composeButtonClick() {
        print("点击下")
    }
}
